using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class MailMgr
{
    private static MailMgr _instance;

    public static MailMgr Instance
    {
        get
        {
            if (_instance == null)
            {
                _instance = new MailMgr();
            }

            return _instance;
        }
    }

    private MailMgr()
    {
    }

    public List<MailItemData> Datas = new List<MailItemData>();


    public void Init()
    {
        Datas.Clear();
        for (int i = 0; i < 50; i++)
        {
            Datas.Add(new MailItemData()
            {
                id = (ulong)(100000 + i),
                isNotRead = i % 2 == 0 ? true : false
            });
        }

        RefreshRedPoint();
    }

    private void RefreshRedPoint()
    {
        foreach (var itemData in Datas)
        {
            var node = RedPointMgr.Instance.GetNode(ERedPoint.Mail).GetOrAddRedPointNode(itemData.id);
            node.AddOnRedPointCheckListener(() => { return itemData.isNotRead ? 1 : 0; },true);
        }
    }

    /// <summary>
    /// 设置已读
    /// </summary>
    /// <param name="id"></param>
    public void SetReaded(ulong id)
    {
        foreach (var itemData in Datas)
        {
            if (itemData.id == id)
            {
                itemData.isNotRead = false;
            }
        }

        RefreshRedPoint();
    }

    public void Release()
    {
        Datas.Clear();
    }
}

public class MailItemData
{
    public ulong id;
    public bool isNotRead; //是否未读
}